<template>
	<view class="page">
		<view class="list" v-if="dataList && dataList.length > 0">
			<view class="item" v-for="(item,index) in dataList" :key="item.id" @tap="choose(item)">
				<view class="name">
					<view class="left">
						<text>{{item.name}}</text> <text v-if="common.store && common.store.id == item.id">当前选择</text>
					</view>
					<!-- <image @tap="getStoreInfo(item)" src="/static/restaurant/common/info.png" mode="widthFix"></image> -->
				</view>
				<view class="address">
					{{item.citys}} {{item.address}}
				</view>
			</view>
		</view>
		<s-empty v-if="dataList && dataList.length == 0"></s-empty>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				dataList: null
			}
		},
		computed: {
			...mapState(['user', 'common'])
		},
		onLoad() {
			this.loadData()
		},
		onPullDownRefresh() {
			this.loadData();
		},
		methods: {
			async loadData(item) {
				let res = await this.$api.getStoreLists();
				if (res.code == 1) {
					this.dataList = res.data
				}

			},
			choose(item) {
				if(item.content) {
					item.content = item.content.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, (
						match, capture) => {
						var img =
							`<img style="display: block; max-width: 100%;" src="${this.$wanlshop.oss(capture)}">`;
						return img;
					});
				}
				this.$store.dispatch('common/setStore', item);
				let pages = getCurrentPages(); // 获取当前页面栈的实例
				let prevPage = pages[pages.length - 2]; //上一个页面
				// if(prevPage) {
				// 	uni.navigateBack({
				// 		delta: 1
				// 	});
				// } else {
					this.$wanlshop.on('/pages/restaurant/user')
				// }
			},
			getStoreInfo(item) {

			}
		}
	}
</script>

<style>
	page {
		background-color: #fff;
	}
</style>
<style lang="less" scoped>
	.list {
		.item {
			padding: 20rpx 30rpx;

			.name {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 10rpx;

				image {
					width: 30rpx;
					height: 30rpx;
				}

				.left {
					display: flex;
					justify-content: flex-start;
					align-items: center;

					text {
						&:nth-child(1) {
							color: #333;
							font-size: 32rpx;
							font-weight: 500;
						}

						&:nth-child(2) {
							font-size: 22rpx;
							background-color: #FA802A;
							padding: 2rpx 10rpx;
							border-radius: 20rpx 20rpx 20rpx 0;
							display: inline-block;
							color: #fff;
							margin-left: 20rpx;
						}
					}
				}
			}

			.address {
				font-size: 28rpx;
				color: #999999;
			}
		}
	}
</style>